package com.dzh.xdyy;

import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;

public class Mp3Util {

    private static MediaPlayer mp = new MediaPlayer();

    public static void play(AssetManager assets,String mp3){
        try {
            AssetFileDescriptor fileDescriptor = assets.openFd(mp3);
            mp.setDataSource(fileDescriptor.getFileDescriptor(),
                    fileDescriptor.getStartOffset(),fileDescriptor.getLength());
            mp.setVolume(1.0f, 1.0f);
            mp.prepareAsync();//mp.prepare();
            mp.setOnPreparedListener((m)->{m.start();});// 装载完毕回调
        }catch(Exception e){

        }
    }

    public static void reset(){
        mp.reset();
    }
}
